package com.liveneo.adapter.mobile.web.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.liveneo.adapter.base.entity.PrpmCaseInfo78;
import com.liveneo.adapter.base.entity.PrpmCaseInfoLossItemCyp;
import com.liveneo.adapter.base.entity.PrpmLossItem78;
import com.liveneo.adapter.base.entity.PrpmLossItemCheckCyp;
import com.liveneo.adapter.base.entity.PrpmLossItemCyp;
import com.liveneo.adapter.base.entity.PrpmLossItemCypHistory;
import com.liveneo.adapter.base.entity.PrpmOrg;
import com.liveneo.adapter.base.entity.PrpmUploadLossItemImg;
import com.liveneo.adapter.base.entity.PrpmVerifyResultInfo;
import com.liveneo.adapter.base.support.AdapterConstants;
import com.liveneo.adapter.base.support.BaseController;
import com.liveneo.adapter.base.support.LogUtils;
import com.liveneo.adapter.mobile.model.dto.AuditionResultDto;
import com.liveneo.adapter.mobile.model.dto.CaseInfoDtoPn;
import com.liveneo.adapter.mobile.model.dto.CaseInfoLossItemDto;
import com.liveneo.adapter.mobile.model.dto.CaseInfoRegistDto;
import com.liveneo.adapter.mobile.model.dto.PolicyDto;
import com.liveneo.adapter.mobile.model.dto.PolicyItemDto;
import com.liveneo.adapter.mobile.model.dto.PrpmLossitemcheck78Dto;
import com.liveneo.adapter.mobile.model.dto.ReviewImage;
import com.liveneo.adapter.mobile.model.dto.VerifyResultDto;
import com.liveneo.adapter.mobile.model.request.AuditionResultRequest;
import com.liveneo.adapter.mobile.model.request.BodyhurtInfoRequest;
import com.liveneo.adapter.mobile.model.request.CareOfOtherRequest;
import com.liveneo.adapter.mobile.model.request.CaseListNotHandleRequest;
import com.liveneo.adapter.mobile.model.request.ChangeTaskStatusRequest;
import com.liveneo.adapter.mobile.model.request.CreateTaskRequest;
import com.liveneo.adapter.mobile.model.request.RegistInfoRequest;
import com.liveneo.adapter.mobile.model.request.SurveyFinishRequest;
import com.liveneo.adapter.mobile.model.response.AuditionResultResponse;
import com.liveneo.adapter.mobile.model.response.BodyhurtInfoResponse;
import com.liveneo.adapter.mobile.model.response.CareOfOtherResponse;
import com.liveneo.adapter.mobile.model.response.CaseListNotHandleResponse;
import com.liveneo.adapter.mobile.model.response.CreateTaskResponse;
import com.liveneo.adapter.mobile.model.response.RegistInfoResponse;
import com.liveneo.adapter.mobile.model.response.SurveyFinishResponse;
import com.liveneo.adapter.mobile.service.PrpmCaseInfoLossItemCypService;
import com.liveneo.adapter.mobile.service.PrpmLossItemCheckCypService;
import com.liveneo.adapter.mobile.service.PrpmLossItemCypHistoryService;
import com.liveneo.adapter.mobile.service.PrpmLossItemCypService;
import com.liveneo.adapter.mobile.service.PrpmOrgService;
import com.liveneo.adapter.mobile.service.PrpmUploadLossItemImgService;
import com.liveneo.adapter.mobile.service.VerifyResultInfoService;
import com.liveneo.adapter.mobile.support.MobileReturnCodeSupport;
import com.liveneo.adapter.mobile.util.DateUtil;
import com.liveneo.adapter.mobile.util.UUIDUtils;
import com.liveneo.adapter.outinterface.util.ResultInfo;
import com.liveneo.adapter.outinterface.web.platform.ClaimInterface;
import com.liveneo.adapter.outinterface.web.platform.request.ChangeTaskStatus;
import com.liveneo.adapter.webservice.server.claim.CaseInfo;
import com.liveneo.adapter.webservice.server.claim.model.Claim2VsRequest;
import com.liveneo.adapter.webservice.server.claim.model.Claim2VsResponse;
import com.liveneo.adapter.webservice.server.claim.model.dto.Claim2VsServiceManage;
import com.liveneo.system.base.utils.Constant;
import com.liveneo.system.base.utils.DateUtils;
import com.liveneo.system.base.utils.JsonUtils;
import com.liveneo.system.base.utils.OssManage;
import com.liveneo.system.base.utils.TransModelUtil;

/**
 * @Desc：任务相关接口
 * @Title：MobileSurveyFinishController
 * @address: http://www.liveneo.com.cn/
 * @author: zhaoyy
 * @version: 1.0
 * @date: 2016年10月9日 下午10:05:39
 */
@Controller
@RequestMapping("/mobile")
public class MobileSurveyFinishController extends BaseController {
    @Autowired
    private PrpmLossItemCypService         lossItemCypService;
    // @Autowired
    // private CheckUserService checkUserService;
    // @Autowired
    // private CaseInfo78Service caseInfo78Service;
    @Autowired
    private VerifyResultInfoService        verifyResultInfoService;
    @Autowired
    private PrpmUploadLossItemImgService   uploadLossItemimgService;
    // @Autowired
    // private PrpmLossitemcheck78Service lossitemcheck78Service;
    @Autowired
    private PrpmOrgService                 orgService;
    // @Autowired
    // private Video78Service video78Service;
    @Autowired
    private PrpmLossItemCypHistoryService  lossItemCypHistoryService;
    @Autowired
    private PrpmCaseInfoLossItemCypService caseInfoLossItemCypService;
    @Autowired
    private PrpmLossItemCheckCypService    lossItemCheckCypService;

    /**
     * MP53
     * @Desc: 修改任务状态
     * @Title: 修改任务状态
     * @Author: zhaoyy 2016年10月14日 上午10:18:53
     * @param data
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @ResponseBody
    @RequestMapping("/surveyFinish78.action")
    public String surveyFinish78(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP53入参=" + loguuid;
        SurveyFinishRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, SurveyFinishRequest.class); // 解析请求参数
        SurveyFinishResponse response = null;
        String result = "";
        String lossUuid = request.getLossUuid();        // 损失项唯一标识
        String caseNo = request.getCaseNo(); // 案件号
        try {
            if (StringUtils.isBlank(lossUuid)) {
                response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        SurveyFinishResponse.class);
            } else {
                // 根据损失项唯一标识查询损失项
                PrpmLossItemCyp prpmLossItemCyp = lossItemCypService.selectByPrimaryKey(lossUuid);
                Map param = new HashMap();
                param.put("UUID", request.getLossUuid());
                param.put("updateTime", new Date());
                if (null != prpmLossItemCyp && prpmLossItemCyp.getLossType() == 9) {
                    // TODO 案件任务状态同步到调度
                    ChangeTaskStatus taskStatus = new ChangeTaskStatus();
                    taskStatus.setCaseNo(prpmLossItemCyp.getCaseNo());
                    taskStatus.setCaseUuid(prpmLossItemCyp.getCaseInfoCypId());
                    taskStatus.setLicenseNo(prpmLossItemCyp.getVehicleModle());
                    taskStatus.setContact(prpmLossItemCyp.getContact());
                    taskStatus.setContactPhone(prpmLossItemCyp.getContactPhone());
                    taskStatus.setCollectAddress(prpmLossItemCyp.getCollectAddress());
                    taskStatus.setCollectTime(prpmLossItemCyp.getCollectTime() != null ? DateUtil.formatDate(prpmLossItemCyp.getCollectTime()) : "");
                    taskStatus.setRemark(prpmLossItemCyp.getRemark());
                    // PrpmCaseInfo78 prpmCaseInfo78 = caseInfo78Service.getCaseInfo(caseNo);
                    // taskStatus.setDamageDate(prpmCaseInfo78.getDamageDate() != null ?
                    // DateUtil.formatDate(prpmCaseInfo78.getDamageDate()) : "");
                    // taskStatus.setDamagePlace(prpmCaseInfo78.getDamagePlace());
                    taskStatus.setInformation(prpmLossItemCyp.getInformation());
                    // taskStatus.setReassignReType("修改任务状态");
                    // taskStatus.setReassignMsg("修改任务状态");
                    taskStatus.setStatus("1");// 未处理
                    ResultInfo resultInfo = ClaimInterface.changeTaskStatus(taskStatus);
                    if (null == resultInfo) {
                        response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE,
                                "查勘状态变更同步到调度失败:无返回信息", SurveyFinishResponse.class);
                    } else {
                        if (null != resultInfo && "000".equals(resultInfo.getResultCode())) {
                            int count = lossItemCypService.updateStatusByUuid(param);
                            if (count == 1) {
                                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                        SurveyFinishResponse.class);
                            } else {
                                response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE,
                                        "同步调度成功，修改查勘平台数据失败！", SurveyFinishResponse.class);
                            }
                        } else {
                            response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE,
                                    "查勘状态变更同步到调度失败:" + resultInfo.getResultMsg(), SurveyFinishResponse.class);
                        }
                    }
                } else {
                    int count = lossItemCypService.updateStatusByUuid(param);
                    if (count == 1) {
                        response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                SurveyFinishResponse.class);
                    } else {
                        response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "修改查勘平台数据失败！",
                                SurveyFinishResponse.class);
                    }
                }
            }
        } catch (Exception e) {
            LogUtils.error("MP53修改任务状态==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse2(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, e.getMessage(),
                    SurveyFinishResponse.class);
        } finally {
            result = decorateResult("MP53修改任务状态", response);
        }
        return result;
    }

    /**
     * MP45
     * @Desc: 根据查勘员的手机号查询待处理任务列表
     * @Title: 获取待处理任务列表
     * @Author: zhaoyy 2016年10月14日 上午10:20:10
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/getCaseListForPhoneNo.action")
    public String getCaseListForPhoneNo(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP45入参=" + loguuid;
        CaseListNotHandleRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, CaseListNotHandleRequest.class); // 解析请求参数
        CaseListNotHandleResponse response = null;
        String result = "";
        String userCode = request.getUserCode();  // 用户编码
        String caseNo = request.getCaseNo();      // 案件号
        try {
            if (StringUtils.isBlank(userCode)) {
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        CaseListNotHandleResponse.class);
            } else {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("userCode", request.getUserCode());
                if (StringUtils.isNotBlank(caseNo)) {
                    map.put("caseNo", request.getCaseNo());
                }
                // 根据用户编码和案件号查询损失列表
                List<PrpmLossItemCyp> prpmLossItemList = lossItemCypService.selectLossByUserCodeAndCaseNo(map);// 根据手机号查prpmlossitem
                List<CaseInfoDtoPn> caseInfoList = new ArrayList<CaseInfoDtoPn>();
                if (CollectionUtils.isNotEmpty(prpmLossItemList)) {
                    for (PrpmLossItemCyp prpmLoss : prpmLossItemList) {
                        CaseInfoDtoPn caseInfoDto = new CaseInfoDtoPn();
                        caseInfoDto.setCaseNo(prpmLoss.getCaseNo());
                        caseInfoDto.setCaseUuid(prpmLoss.getCaseInfoCypId());
                        caseInfoDto.setHandleStatus(prpmLoss.getHandleStatus());
                        caseInfoDto.setLossUuid(prpmLoss.getLossItemCypId());
                        caseInfoDto.setVerifyTime(prpmLoss.getVerifyTime() == null ? "0" : String.valueOf(prpmLoss.getVerifyTime()));
                        caseInfoList.add(caseInfoDto);
                    }
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            CaseListNotHandleResponse.class);
                    response.setCaseInfoList(caseInfoList);
                } else {
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            CaseListNotHandleResponse.class);
                    response.setCaseInfoList(caseInfoList);
                }
            }
        } catch (Exception e) {
            LogUtils.error("MP45获取待处理任务列表==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    CaseListNotHandleResponse.class);
        } finally {
            result = decorateResult("MP45获取待处理任务列表", response);
        }
        return result;
    }

    /**
     * MP46  此接口废除
     * @Desc: 1、根据案件号校验案件状态
     * @Title: 创建单证任务
     * @Author: zhaoyy 2016年10月14日 上午10:21:29
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/createDocumentTaskServlet.action")
    public String CreateDocumentTaskServlet(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP46入参=" + loguuid;
        CreateTaskRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, CreateTaskRequest.class); // 解析请求参数
        CreateTaskResponse response = new CreateTaskResponse();
        String result = "";
        PrpmLossItem78 prpmLossItem78 = new PrpmLossItem78();
        PrpmCaseInfo78 prpmCaseInfo78 = new PrpmCaseInfo78();
        try {
            // PrpmCheckUser checkUser = null;
            // checkUserService.findUserByPhone(request.getMobile());
            List<PrpmCaseInfoLossItemCyp> prpmCaseInfoLosstiem78 = null;
            // caseInfo78Service.PrpmCaseInfoLosstiem78ByCaseNo(request.getCaseNo());
            PrpmCaseInfo78 prpmCaseInfoNo78 = null;
            // caseInfo78Service.getCaseInfo(request.getCaseNo());
            PolicyDto policyDto = new PolicyDto();
            CaseInfo caseInfo = new CaseInfo();
            caseInfo.setRegistNo(request.getCaseNo());
            Claim2VsRequest claim2VsRequest = new Claim2VsRequest();
            claim2VsRequest.setCaseinfo(caseInfo);
            Claim2VsServiceManage claim2VsServiceManage = new Claim2VsServiceManage();
            try {
                // 调用理赔获取定损单方法，返回定损单信息
                Claim2VsResponse claim2VsResponse = claim2VsServiceManage.getResponse(claim2VsRequest, "P12", "");
                if (claim2VsResponse.getVsResponseHeadDto().getResultCode() == "000" || "000".equals(claim2VsResponse.getVsResponseHeadDto().getResultCode())) {
                    policyDto = (new TransModelUtil()).turnsToPolicyDto(claim2VsResponse, Constant.NOCASE_UUID);
                } else {
                    throw new Exception();
                }
            } catch (Exception e) {
                e.printStackTrace();
                LogUtils.error("<案件信息查询（保单）>异常::caseNo=" + request.getCaseNo() + ">" + e.toString());
            }
            if (prpmCaseInfoNo78 == null) {// 如果原来没有创建该案件
                if (prpmCaseInfoLosstiem78 == null || prpmCaseInfoLosstiem78.size() == 0) {
                    prpmCaseInfo78.setContact(request.getContact());// 联系人
                    prpmCaseInfo78.setUuid(loguuid);
                    prpmCaseInfo78.setCaseNo(request.getCaseNo());
                    // prpmCaseInfo78.setCompanyUuid(checkUser.getCompanyuuid());
                    prpmCaseInfo78.setLicenseNo(request.getLicenseNo());
                    prpmCaseInfo78.setContactPhone(request.getContactPhone());// 联系电话
                    prpmCaseInfo78.setRemark(request.getRemark());// 备注
                    prpmCaseInfo78.setDamagePlace(request.getDamagePlace());// 出险地点
                    prpmCaseInfo78.setDamageDate(request.getDamageDate());// 出险时间
                    prpmCaseInfo78.setCreateTime(new Date());
                    if (policyDto != null && policyDto.getPolicyItemDtoList() != null && policyDto.getPolicyItemDtoList().size() > 0) {
                        List<PolicyItemDto> policyItemDtoList = policyDto.getPolicyItemDtoList();
                        if (policyItemDtoList.size() == 1) {
                            PolicyItemDto policyItemDto = policyItemDtoList.get(0);
                            prpmCaseInfo78.setPolicyCode(policyItemDto.getPolicyNo());
                            prpmCaseInfo78.setPolicyHolder(policyItemDto.getTbName());
                            prpmCaseInfo78.setInsuranceType(policyItemDto.getRiskName());
                            prpmCaseInfo78.setInsuranceClass(policyItemDto.getRiskClass());
                            prpmCaseInfo78.setUserName(policyItemDto.getInsurantName());
                        } else {
                            for (PolicyItemDto policyItemDto : policyItemDtoList) {
                                if (policyItemDto.getRiskName().contains("商业险")) {
                                    prpmCaseInfo78.setPolicyCode(policyItemDto.getPolicyNo());
                                    prpmCaseInfo78.setPolicyHolder(policyItemDto.getTbName());
                                    prpmCaseInfo78.setInsuranceType(policyItemDto.getRiskName());
                                    prpmCaseInfo78.setInsuranceClass(policyItemDto.getRiskClass());
                                    prpmCaseInfo78.setUserName(policyItemDto.getInsurantName());
                                }
                            }
                        }
                    }
                    // caseInfo78Service.insert(prpmCaseInfo78);
                    prpmLossItem78.setClaimStatus("1");// 认领状态
                    prpmLossItem78.setCaseNo(request.getCaseNo());
                    prpmLossItem78.setMobile(request.getMobile());
                    // prpmLossItem78.setSurveyorCode(checkUser.getUsecode());
                    // prpmLossItem78.setSurveyorName(checkUser.getName());
                    prpmLossItem78.setCaseUuid(loguuid);//
                    prpmLossItem78.setCaseSource(3);
                    prpmLossItem78.setContact(request.getContact());
                    prpmLossItem78.setContactPhone(request.getContactPhone());
                    prpmLossItem78.setUuid(loguuid);
                    prpmLossItem78.setCreateTime(new Date());
                    prpmLossItem78.setCollectAddress(request.getCollectAddress());// 收集地点
                    prpmLossItem78.setCollectTime(request.getCollectTime());// 收集时间
                    prpmLossItem78.setInformation(request.getInformation());// 材料内容
                    prpmLossItem78.setHandleStatus("0");// 处理状态 0未上传
                    prpmLossItem78.setLossType(9);// 损失类型
                    // lossItem78Service.insert(prpmLossItem78);
                    response.setLossItemUuid(prpmLossItem78.getUuid());
                    response.setCaseUuid(prpmLossItem78.getCaseUuid());
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            CreateTaskResponse.class);
                } else {
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                            CreateTaskResponse.class);
                }
            } else if (prpmCaseInfoNo78 != null) {// 如果原来已经创建该案件
                if (prpmCaseInfoLosstiem78 == null || prpmCaseInfoLosstiem78.size() == 0) {
                    prpmLossItem78.setCaseNo(request.getCaseNo());
                    prpmLossItem78.setMobile(request.getMobile());
                    // prpmLossItem78.setSurveyorCode(checkUser.getUsecode());
                    // prpmLossItem78.setSurveyorName(checkUser.getName());
                    prpmLossItem78.setCaseUuid(prpmCaseInfoNo78.getUuid());
                    prpmLossItem78.setCaseSource(3);
                    prpmLossItem78.setUuid(loguuid);
                    prpmLossItem78.setContact(request.getContact());
                    prpmLossItem78.setContactPhone(request.getContactPhone());
                    prpmLossItem78.setCreateTime(new Date());
                    prpmLossItem78.setCollectAddress(request.getCollectAddress());// 收集地点
                    prpmLossItem78.setCollectTime(request.getCollectTime());// 收集时间
                    prpmLossItem78.setInformation(request.getInformation());// 材料内容
                    prpmLossItem78.setHandleStatus("0");// 处理状态 0未上传
                    prpmLossItem78.setLossType(9);// 损失类型
                    prpmLossItem78.setClaimStatus("1");// 认领状态
                    // lossItem78Service.insert(prpmLossItem78);
                    response.setLossItemUuid(prpmLossItem78.getUuid());
                    response.setCaseUuid(prpmLossItem78.getCaseUuid());
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            CreateTaskResponse.class);
                } else {
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                            CreateTaskResponse.class);
                }
            }
        } catch (Exception e) {
            LogUtils.error("创建单证任务出错，错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    CreateTaskResponse.class);
        } finally {
            result = decorateResult(response);
        }
        return result;
    }

    /**
     * MP48
     * @Desc: 申请改派（单证任务的）
     * @Title: 单证任务申请改派
     * @Author: zhaoyy 2016年10月14日 上午10:23:04
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/careOfOther.action")
    public String careOfOther(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP48入参=" + loguuid;
        CareOfOtherRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, CareOfOtherRequest.class); // 解析请求参数
        CareOfOtherResponse response = new CareOfOtherResponse();
        String result = "";
        String lossUuid = request.getLossUuid();        // 案件唯一标识
        try {
            if (StringUtils.isBlank(lossUuid)) {
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        CareOfOtherResponse.class);
            } else {
                PrpmLossItemCyp lossItemCyp = lossItemCypService.selectByPrimaryKey(lossUuid);
                // 更新状态信息
                lossItemCyp.setLossItemCypId(request.getLossUuid());
                lossItemCyp.setContact(request.getContact());
                lossItemCyp.setContactPhone(request.getContactPhone());
                lossItemCyp.setCollectAddress(request.getSurveyPalce());
                lossItemCyp.setCollectTime(request.getSurveyDate());
                lossItemCyp.setInformation(request.getInformation());
                lossItemCyp.setRemark(request.getOtherRemark());
                lossItemCyp.setModifyTime(new Date());
                lossItemCyp.setHandleStatus("6");// 申请改派
                // 记录历史信息
                PrpmLossItemCypHistory lossitem78History = new PrpmLossItemCypHistory();
                lossitem78History.setCreateTime(new Date());
                lossitem78History.setModifyTime(new Date());
                lossitem78History.setReassignmentCause(request.getReassignmentCause());
                lossitem78History.setReassignmentReason(request.getReassignmentReason());
                lossitem78History.setAuditorCode(lossItemCyp.getAuditorCode());
                lossitem78History.setAuditorName(lossItemCyp.getAuditorName());
                lossitem78History.setCaseNo(lossItemCyp.getCaseNo());
                // lossitem78History.setCaseSource(lossItemCyp.getCaseSource());
                lossitem78History.setCaseInfoCypId(lossItemCyp.getCaseInfoCypId());
                lossitem78History.setClaimStatus(lossItemCyp.getClaimStatus());
                lossitem78History.setCollectAddress(lossItemCyp.getCollectAddress());
                // 人伤材料收集人电话
                // lossitem78History.setCollectorPhone(lossItemCyp.getCollectorPhone());
                lossitem78History.setCollectTime(lossItemCyp.getCollectTime());
                lossitem78History.setContact(lossItemCyp.getContact());
                lossitem78History.setContactPhone(lossItemCyp.getContactPhone());
                lossitem78History.setSurveyorName(lossItemCyp.getSurveyorName());
                // 是否有效
                // lossitem78History.setEnabled(lossItemCyp.getEnabled());
                lossitem78History.setFinishCaseTime(lossItemCyp.getFinishCaseTime());
                // 标志位：预留字段 1表示查勘员已定损确认，手机端不用再显示
                // lossitem78History.setFlag(lossItemCyp.getFlag());
                lossitem78History.setHandleStatus(lossItemCyp.getHandleStatus());
                lossitem78History.setInformation(lossItemCyp.getInformation());
                lossitem78History.setInjuryAge(lossItemCyp.getInjuryAge());
                lossitem78History.setInjuryContent(lossItemCyp.getInjuryContent());
                lossitem78History.setInjuryIdNo(lossItemCyp.getInjuryIdNo());
                lossitem78History.setInjuryIdType(lossItemCyp.getInjuryIdType());
                lossitem78History.setInjuryName(lossItemCyp.getInjuryName());
                lossitem78History.setInjurySex(lossItemCyp.getInjurySex());
                lossitem78History.setInjuryType(lossItemCyp.getInjuryType());
                lossitem78History.setLossItemCypId(lossItemCyp.getLossItemCypId());
                lossitem78History.setLossType(lossItemCyp.getLossType());
                lossitem78History.setMobile(lossItemCyp.getMobile());
                lossitem78History.setObjectName(lossItemCyp.getObjectName());
                lossitem78History.setRemark(lossItemCyp.getRemark());
                lossitem78History.setSurveyorCode(lossItemCyp.getSurveyorCode());
                lossitem78History.setSurveyorName(lossItemCyp.getSurveyorName());
                lossitem78History.setSurveyUnitCode(lossItemCyp.getSurveyUnitCode());
                lossitem78History.setSurveyorName(lossItemCyp.getSurveyorName());
                lossitem78History.setVehicleModle(lossItemCyp.getVehicleModle());
                lossitem78History.setVerifyTime(lossItemCyp.getVerifyTime());
                // 状态变更同步到调度信息
                ChangeTaskStatusRequest changeTaskStatusRequest = new ChangeTaskStatusRequest();
                ChangeTaskStatus changeTaskStatus = new ChangeTaskStatus();
                changeTaskStatus.setCaseNo(request.getCaseNo());
                changeTaskStatus.setCaseUuid(request.getCaseUuid());
                changeTaskStatus.setCollectAddress(request.getSurveyPalce());
                if (request.getSurveyDate() != null) {
                    changeTaskStatus.setCollectTime(DateUtils.formatDateTime(request.getSurveyDate()));
                }
                changeTaskStatus.setContact(request.getContact());
                changeTaskStatus.setContactPhone(request.getContactPhone());
                if (request.getDamageDate() != null) {
                    changeTaskStatus.setDamageDate(DateUtils.formatDateTime(request.getDamageDate()));
                }
                changeTaskStatus.setDamagePlace(request.getDamagePlace());
                changeTaskStatus.setInformation(request.getInformation());
                changeTaskStatus.setLicenseNo(request.getLicenceNo());
                changeTaskStatus.setReassignMsg(request.getReassignmentReason());
                changeTaskStatus.setReassignReType(request.getReassignmentCause());
                changeTaskStatus.setRemark(request.getOtherRemark());
                changeTaskStatus.setStatus("6");
                changeTaskStatusRequest.setChangeTaskStatus(changeTaskStatus);
                // 状态变更同步到调度
                ResultInfo resultInfo = ClaimInterface.changeTaskStatus(changeTaskStatus);
                if ("000".equals(resultInfo.getResultCode())) {
                    LogUtils.info(request.getCaseNo() + "MP48查勘状态变更同步到调度成功!");
                    // 申请改派更新lossItem78数据
                    int ret = lossItemCypService.updateToSurPeoByCaseNo(lossItemCyp);
                    if (ret > 0) {
                        response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                CareOfOtherResponse.class);
                        response.setIsBindingSuccess("1");
                    } else {
                        response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                CareOfOtherResponse.class);
                        response.setIsBindingSuccess("0");
                    }
                    lossitem78History.setLossItemCypHistoryId(UUIDUtils.getUUIDStr());
                    // 增加历史记录
                    lossItemCypHistoryService.insertLossItemCypHistory(lossitem78History);
                } else {
                    LogUtils.info(request.getCaseNo() + "MP48查勘状态变更同步到调度失败:" + resultInfo.getResultMsg());
                    response.setResultCode(MobileReturnCodeSupport.CODE_FAIL);
                    response.setExtMessage("MP48查勘状态变更同步到调度失败，失败信息：" + resultInfo.getResultMsg());
                    response.setSystemCode(MobileReturnCodeSupport.SYS_CODE);
                }
            }
        } catch (Exception e) {
            LogUtils.error("MP48单证任务申请改派==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    CareOfOtherResponse.class);
        } finally {
            result = decorateResult("MP48单证任务申请改派", response);
        }
        return result;
    }

    /**
     * MP54
     * @Desc: 人伤预审核结果查询
     * @Title: 人伤预审核结果查询
     * @Author: zhaoyy 2016年10月14日 上午10:24:43
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/getAuditionResult.action")
    public String getAuditionResult(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP54入参=" + loguuid;
        AuditionResultRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, AuditionResultRequest.class); // 解析请求参数
        AuditionResultResponse response = null;
        String result = "";
        try {
            if (StringUtils.isBlank(request.getLossItemUuid())) {
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        AuditionResultResponse.class);
            } else {
                PrpmCaseInfoLossItemCyp caseinfo = lossItemCypService.getAuditionResultByUuid(request.getLossItemUuid());
                AuditionResultDto auditionResultDto = new AuditionResultDto();
                if (caseinfo != null) {
                    auditionResultDto.setCaseNo(caseinfo.getCaseNo());
                    auditionResultDto.setInjuryAge(caseinfo.getInjuryAge() + "");
                    auditionResultDto.setInjuryIDNo(caseinfo.getInjuryIdNo());
                    auditionResultDto.setInjuryName(caseinfo.getInjuryName());
                    auditionResultDto.setInjurySex(caseinfo.getInjurySex());
                    auditionResultDto.setLicenceNo(caseinfo.getLicenseNo());
                    auditionResultDto.setUserName(caseinfo.getUserName());
                    List<PrpmVerifyResultInfo> verifyResultList = verifyResultInfoService.selectByLossItemUuid(request.getLossItemUuid());
                    List<VerifyResultDto> verifyResultDtoList = new ArrayList<VerifyResultDto>();
                    if (verifyResultList != null) {
                        BigDecimal totalAmount = new BigDecimal(0.00);
                        String standard = "";
                        for (int i = 0; i < verifyResultList.size(); i++) {
                            VerifyResultDto verifyResultDto = new VerifyResultDto();
                            verifyResultDto.setAmount(verifyResultList.get(i).getAmount());
                            verifyResultDto.setName(verifyResultList.get(i).getName());
                            standard = verifyResultList.get(i).getStandard();
                            if (StringUtils.isNotEmpty(standard)) {
                                standard = standard.trim();
                                if (!standard.endsWith("元")) {
                                    if (!"无".equals(standard)) {
                                        standard = standard + "元";
                                    }
                                }
                            }
                            verifyResultDto.setStandard(standard);
                            standard = "";
                            totalAmount = totalAmount.add(new BigDecimal(verifyResultList.get(i).getAmount()));
                            verifyResultDtoList.add(verifyResultDto);
                        }
                        auditionResultDto.setTotalAmount(totalAmount != null ? totalAmount.toString() + "元" : "");
                    }
                    auditionResultDto.setVerifyResultList(verifyResultDtoList);
                }
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                        AuditionResultResponse.class);
                response.setAuditionResultDto(auditionResultDto);
            }
        } catch (Exception e) {
            LogUtils.error("MP54人伤预审核结果==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    AuditionResultResponse.class);
        } finally {
            result = decorateResult("MP54人伤预审核结果", response);
        }
        return result;
    }

    /**
     * MP56
     * 获取人伤预审核案件列表
     * @author zhaoyy 2016年10月11日 下午5:50:17
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/getRegistInfo78.action")
    public String getRegistInfo78(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP56入参=" + loguuid;
        RegistInfoRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, RegistInfoRequest.class); // 解析请求参数
        RegistInfoResponse response = null;
        String result = "";
        String phoneNo = request.getPhoneNo();         // 手机号
        try {
            if (StringUtils.isBlank(phoneNo)) {
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        RegistInfoResponse.class);
            } else {
                List<PrpmLossItem78> prpmLossItemList = null;
                // lossItem78Service.getLossItemByPhoneNo(phoneNo);// 根据手机号查prpmlossitem
                List<CaseInfoRegistDto> caseInfoList = new ArrayList<CaseInfoRegistDto>();
                List<String> caseUUidList = new ArrayList<String>();
                // 取出caseUUid放入list,此时caseUUid为重复的
                if (prpmLossItemList != null && prpmLossItemList.size() > 0) {
                    for (PrpmLossItem78 item : prpmLossItemList) {
                        if (item.getLossType() == 8) {
                            String caseUUid = item.getCaseUuid();
                            caseUUidList.add(caseUUid);
                        }
                    }
                    List<String> caseUIDList = new ArrayList<String>();// 存放去重后的caseUUid
                    if (caseUUidList != null && caseUUidList.size() > 0) {
                        for (String s : caseUUidList) {
                            if (Collections.frequency(caseUIDList, s) < 1) caseUIDList.add(s);
                        }
                        List<PrpmCaseInfo78> caseList = null;
                        // caseInfo78Service.getCaseInfo(caseUIDList);// 获取caseUUid获取prpmcaseinfo
                        if (caseList != null && caseList.size() > 0) {
                            for (int i = 0; i < caseList.size(); i++) {
                                PrpmOrg org = orgService.findByCompanyCode(caseList.get(i).getCompanyCode());
                                CaseInfoRegistDto caseInfoDto = new CaseInfoRegistDto();
                                BeanUtils.copyProperties(caseInfoDto, caseList.get(i));
                                caseInfoDto.setFinishCaseTimeTemp(caseList.get(i).getCreateTime());
                                if (org != null && !"".equals(org)) {
                                    caseInfoDto.setVcid(org.getOrgVcid());
                                    caseInfoDto.setSkillID(org.getOrgSkill());
                                }
                                String agtID = "";
                                // video78Service.getRecentAgtID(caseList.get(i).getUuid());
                                caseInfoDto.setAgtID(agtID);
                                caseInfoList.add(caseInfoDto);
                            }
                            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                    RegistInfoResponse.class);
                            response.setCaseInfoList(caseInfoList);
                        } else {
                            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                    RegistInfoResponse.class);
                            response.setCaseInfoList(caseInfoList);
                        }
                    } else {
                        response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                                RegistInfoResponse.class);
                        response.setCaseInfoList(caseInfoList);
                    }
                } else {
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            RegistInfoResponse.class);
                    response.setCaseInfoList(caseInfoList);
                }
            }
        } catch (Exception e) {
            LogUtils.error("MP56人伤预审核结果==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    RegistInfoResponse.class);
        } finally {
            result = decorateResult("MP56人伤预审核结果", response);
        }
        return result;
    }

    /**
     * MP58
     * @Desc: 1.自助端获取案件信息。
     * @Title: 获取人伤预审核列表 
     * @Author: zhaoyy 2016年10月14日 下午3:21:59
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping("/getBodyhurtInfo.action")
    public String getBodyhurtInfo(@ModelAttribute(AdapterConstants.MOBILE_REQUEST_PARAM_NAME) String data) {
        String loguuid = UUIDUtils.getUUIDStr();
        String logTitle = "MP58入参=" + loguuid;
        BodyhurtInfoRequest request = JsonUtils.fromJsonWithBase64(logTitle, data, BodyhurtInfoRequest.class);
        BodyhurtInfoResponse response = null;
        String result = "";
        String phoneNo = request.getPhoneNo();      // 手机号
        try {
            if (StringUtils.isBlank(phoneNo)) {
                response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_FAIL, MobileReturnCodeSupport.SYS_CODE, "参数为空或不完整，请检查参数！",
                        BodyhurtInfoResponse.class);
            } else {
                List<PrpmCaseInfoLossItemCyp> caseList = caseInfoLossItemCypService.getCaseLossDtoByPhoneNo(request.getPhoneNo());
                List<CaseInfoLossItemDto> caseInfoList = new ArrayList<CaseInfoLossItemDto>();
                if (caseList != null && caseList.size() > 0) {
                    for (int i = 0; i < caseList.size(); i++) {
                        List<Map<String, Object>> auditList = lossItemCheckCypService.selectByLossItemUuid(caseList.get(i).getLossItemCypId());
                        String jsonarray = JSONArray.fromObject(auditList).toString();
                        JSONArray array = JSONArray.fromObject(jsonarray);
                        @SuppressWarnings("unchecked")
                        List<PrpmLossItemCheckCyp> auditListNew = JSONArray.toList(array, new PrpmLossItemCheckCyp(), new JsonConfig());
                        List<PrpmLossitemcheck78Dto> auditInfoList = new ArrayList<PrpmLossitemcheck78Dto>();
                        for (int x = 0; x < auditListNew.size(); x++) {
                            String lossItemCheckCypId = auditListNew.get(x).getLossItemCheckCypId();
                            List<PrpmUploadLossItemImg> reviewList = uploadLossItemimgService.selectByCheckUuid(lossItemCheckCypId);
                            List<ReviewImage> reviewImagesList = new ArrayList<ReviewImage>();
                            for (int y = 0; y < reviewList.size(); y++) {
                                ReviewImage reviewImage = new ReviewImage();
                                OssManage ossManage = new OssManage();
                                reviewImage.setOssUrl(ossManage.getImgURl(reviewList.get(y).getOssKey()));
                                reviewImage.setLocalPath(reviewList.get(y).getImgPath());
                                reviewImage.setFileFlag(reviewList.get(y).getIsVideoImg().toString());
                                reviewImagesList.add(reviewImage);
                            }
                            PrpmLossitemcheck78Dto checkDto = new PrpmLossitemcheck78Dto();
                            BeanUtils.copyProperties(checkDto, auditList.get(x));
                            checkDto.setAuditOpinion(auditListNew.get(x).getAuditOpinion());
                            checkDto.setAuditTime(DateUtil.dateToStr(auditListNew.get(x).getModifyTime()));
                            checkDto.setReviewer(auditListNew.get(x).getModifyBy());
                            checkDto.setReviewImagesList(reviewImagesList);
                            auditInfoList.add(checkDto);
                        }
                        CaseInfoLossItemDto caseInfoDto = new CaseInfoLossItemDto();
                        caseInfoDto.setCaseNo(caseList.get(i).getCaseNo());
                        caseInfoDto.setLossItemUuid(caseList.get(i).getLossItemCypId());
                        caseInfoDto.setLicenceNo(caseList.get(i).getLicenseNo());
                        caseInfoDto.setUserName(caseList.get(i).getUserName());
                        caseInfoDto.setContact(caseList.get(i).getContact());
                        caseInfoDto.setContactPhone(caseList.get(i).getContactPhone());
                        caseInfoDto.setDamageDate(DateUtil.date24ToStr(caseList.get(i).getDamageDate()));
                        caseInfoDto.setDamagePlace(caseList.get(i).getDamagePlace());
                        caseInfoDto.setSurveyPalce(caseList.get(i).getSurveyPlace());
                        caseInfoDto.setDelegateReamrk(caseList.get(i).getDelegateReamrk());
                        caseInfoDto.setAuditStatus(Integer.valueOf(caseList.get(i).getHandleStatus()));
                        caseInfoDto.setFinishCaseTimeTemp(DateUtil.dateToStr(caseList.get(i).getFinishCaseTime()));
                        caseInfoDto.setAuditNumber(String.valueOf(caseList.get(i).getVerifyTime()));
                        caseInfoDto.setInjuryName(caseList.get(i).getInjuryName());
                        caseInfoDto.setInjurySex(caseList.get(i).getInjurySex());
                        caseInfoDto.setInjuryAge(caseList.get(i).getInjuryAge() + "");
                        caseInfoDto.setInjuryContent(caseList.get(i).getInjuryContent());
                        caseInfoDto.setAuditInfoList(auditInfoList);
                        caseInfoList.add(caseInfoDto);
                    }
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            BodyhurtInfoResponse.class);
                    response.setCaseInfoList(caseInfoList);
                } else {
                    response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_SUCCESS, MobileReturnCodeSupport.SYS_CODE, null,
                            BodyhurtInfoResponse.class);
                    response.setCaseInfoList(caseInfoList);
                }
            }
        } catch (Exception e) {
            LogUtils.error("MP58获取人伤预审核列表 ==>错误信息:", e);
            response = MobileReturnCodeSupport.buildReponse(MobileReturnCodeSupport.CODE_INTERNAL_ERROR, MobileReturnCodeSupport.SYS_CODE, null,
                    BodyhurtInfoResponse.class);
        } finally {
            result = decorateResult("MP58获取人伤预审核列表", response);
        }
        return result;
    }
}
